//
//  ViewController.m
//  runtimeDemo
//
//  Created by kingboyrang on 2021/10/30.
//  Copyright © 2021 wulanzhou. All rights reserved.
//

#import "ViewController.h"
#import "UIButton+block.h"
#import "MMModel.h"

@interface ViewController ()
@property (nonatomic,strong) MMModel *model;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    /**
    runtime使用

    
    1.关联属性  UIButton+block.h中的setButtonTypeName,buttonTypeName
    2.关联方法: UIButton+block.h中的handleWithBlock方法
    3.交换方法: 系统自带的方法功能不够，给系统自带的方法扩展一些功能，并且保持原有的功能。
      案例查看：UIImage+Image.h文件
    4.获取属性列表            案例：MMModel类getAllIvar方法
    5.获取方法列表            案例：MMModel类getAllMethod方法
    6.对私有属性修改
    7.归档:解档(通过runtime快速的归档与解档) 案例：MMModel类encodeWithCoder与initWithCoder类
    */
    
    self.model = [[MMModel alloc] init];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(100, 100, self.view.frame.size.width-200, 50);
    [btn setTitle:@"测试" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [btn setBackgroundColor:UIColor.yellowColor];
    [btn setButtonTypeName:@"aaaa"];
    [btn handleWithBlock:^(id  _Nullable sender) {
        NSLog(@"获取动态添加的属性值 = %@",btn.buttonTypeName);
    }];
    [self.view addSubview:btn];
    
    //获取所有的属性
    [self.model getAllIvar];
    
    // Do any additional setup after loading the view.
}


@end
